package com.tdk.bts.action;

import java.util.ArrayList;
import java.util.List;

import com.tdk.bts.constants.Constants;
import com.tdk.bts.entity.Theater;
import com.tdk.bts.factory.ObjectFactory;
import com.tdk.bts.service.FilmService;
import com.tdk.bts.service.TheaterService;
import com.tdk.bts.util.Page;
import com.tdk.bts.util.Request;

public class TheaterAction {

	/**
	 * 查询所有的放映厅信息
	 * 
	 * 请求参数
	 * 	pageNo 查询页数
	 * 响应数据
	 * 	Page<Theater>类型的 data		
	 */
	public void findTheatersByPage(Request req)throws Exception {
		TheaterService service = (TheaterService) ObjectFactory
				.getObject("theaterServiceProxy");
		int pageNo = Integer.parseInt(req.getParameter("pageNo"));
		Page<Theater> data = service.findByPageNo(pageNo);
		req.setAttribute("data", data);
	}
	
	/**
	 * 删除一个放映室
	 * 请求参数
	 * 	id 放映室id
	 */
	public void deleteTheater(Request req) throws Exception{
		TheaterService service = (TheaterService) ObjectFactory
				.getObject("theaterServiceProxy");
		service.deleteTheater(Integer.parseInt(req.getParameter("id")));

	}

	/**
	 * 添加一个放映室(名称不能重复)
	 * 请求参数
	 * 	name 放映室名称
	 *  rows 放映室排数[行数]
	 *  cols 放映室列数
	 */
	public void save(Request req) throws Exception{
		TheaterService service = (TheaterService) ObjectFactory
				.getObject("theaterServiceProxy");
		service.addTheater(req.getParameter("name"), Integer.parseInt(req.getParameter("rows")), Integer.parseInt(req.getParameter("cols")));
	}

	/**
	 * 查询所有的放映厅信息
	 * 响应数据
	 * 	List<Theater>类型的 data		
	 */
	public void findAll(Request request) throws Exception{		
		TheaterService service = (TheaterService) ObjectFactory
				.getObject("theaterServiceProxy");
		System.out.println("action begin find theater...");
		List<Theater> list=service.findAll();
		System.out.println("find out "+list.size());
		request.setAttribute("data", list);
	}
	
	
}
